package mypractice;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;


public class Leetcode387 {
    //@Test
    public static int firstUniqChar(String s) {
        HashMap<Character, Integer> count = new HashMap<>();
        int i;
        for (i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count.put(ch, count.getOrDefault(ch, 0) + 1);
        }
        for (i = 0; i < s.length(); i++) {
            if(count.get(s.charAt(i))==1){
                return i;
            }
        }
        return -1;
    }
}
